package com.uvnos4j.matilda.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uvnos4j.matilda.commons.dto.PageParam;
import com.uvnos4j.matilda.commons.dto.QueryParam;
import com.uvnos4j.matilda.commons.utils.MpUtil;
import com.uvnos4j.matilda.system.domain.SysLog;
import com.uvnos4j.matilda.system.mapper.SysLogMapper;
import com.uvnos4j.matilda.system.service.SysLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * 日志 Service 实现
 * <p>
 * Description:日志 Service 实现
 * </p>
 *
 * @author Guo.wl
 * @version v1.0.0
 * @see com.uvnos4j.matilda.system.service.impl
 * @since 2020-08-31 23:19:10
 */
@Service
@Transactional(readOnly = true)
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public IPage<SysLog> findPage(QueryParam param, PageParam pageParam, String orderBy) {
        LambdaQueryWrapper<SysLog> lqw = new LambdaQueryWrapper<>();
        Date startTime = param.getDaytimeValue("startTime");
        Date endTime = param.getDaytimeValue("endTime");
        String title = param.getStringValue("title");
        String requestUri = param.getStringValue("requestUri");
        lqw.ge(startTime != null, SysLog::getCreateDate, startTime);
        lqw.le(endTime != null, SysLog::getCreateDate, endTime);
        lqw.like(StrUtil.isNotBlank(title), SysLog::getTitle, title);
        lqw.like(StrUtil.isNotBlank(requestUri), SysLog::getRequestUri, requestUri);

        Page<SysLog> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        page.setOrders(MpUtil.getOrderList(orderBy));

        return baseMapper.selectPage(page, lqw);
    }

    @Override
    public void export(QueryParam param, PageParam pageParam, String orderBy, String fileDest) {
        // TODO
    }
}
